﻿CREATE TABLE [dbo].[KARDEX](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[IdProducto] [int] NOT NULL,
	[IdDetGuiaEntrada] [int] NULL,
	[IdDetPecosa] [int] NULL,
	[Documento] [nvarchar](max) NULL,
	[Fecha] [datetime] NOT NULL,
	[Costo] [int] NOT NULL,
	[CantEntrada] [int] NOT NULL,
	[CantSalida] [int] NOT NULL,
	[NewCantidad] [int] NOT NULL,
 CONSTRAINT [PK_dbo.KARDEX] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  ForeignKey [FK_dbo.KARDEX_dbo.DETALLE_GUIA_ENTRADA_IdDetGuiaEntrada]    Script Date: 11/17/2014 00:41:42 ******/
ALTER TABLE [dbo].[KARDEX]  WITH CHECK ADD  CONSTRAINT [FK_dbo.KARDEX_dbo.DETALLE_GUIA_ENTRADA_IdDetGuiaEntrada] FOREIGN KEY([IdDetGuiaEntrada])
REFERENCES [dbo].[DETALLE_GUIA_ENTRADA] ([ID])
GO

ALTER TABLE [dbo].[KARDEX] CHECK CONSTRAINT [FK_dbo.KARDEX_dbo.DETALLE_GUIA_ENTRADA_IdDetGuiaEntrada]
GO
/****** Object:  ForeignKey [FK_dbo.KARDEX_dbo.DETALLE_PECOSA_IdDetPecosa]    Script Date: 11/17/2014 00:41:42 ******/
ALTER TABLE [dbo].[KARDEX]  WITH CHECK ADD  CONSTRAINT [FK_dbo.KARDEX_dbo.DETALLE_PECOSA_IdDetPecosa] FOREIGN KEY([IdDetPecosa])
REFERENCES [dbo].[DETALLE_PECOSA] ([ID])
GO

ALTER TABLE [dbo].[KARDEX] CHECK CONSTRAINT [FK_dbo.KARDEX_dbo.DETALLE_PECOSA_IdDetPecosa]
GO
/****** Object:  ForeignKey [FK_dbo.KARDEX_dbo.PRODUCTO_IdProducto]    Script Date: 11/17/2014 00:41:42 ******/
ALTER TABLE [dbo].[KARDEX]  WITH CHECK ADD  CONSTRAINT [FK_dbo.KARDEX_dbo.PRODUCTO_IdProducto] FOREIGN KEY([IdProducto])
REFERENCES [dbo].[PRODUCTO] ([ID])
GO

ALTER TABLE [dbo].[KARDEX] CHECK CONSTRAINT [FK_dbo.KARDEX_dbo.PRODUCTO_IdProducto]
GO
CREATE NONCLUSTERED INDEX [IX_IdDetGuiaEntrada] ON [dbo].[KARDEX] 
(
	[IdDetGuiaEntrada] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_IdDetPecosa] ON [dbo].[KARDEX] 
(
	[IdDetPecosa] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_IdProducto] ON [dbo].[KARDEX] 
(
	[IdProducto] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]